#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back
#define vec vector<int>

int read(){int x = 0,sgn = 1;char ch = getchar();for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);return x*sgn;}

const int N = 310,M = 610,MX = 1000000;

int h[M],a[N][N],b[N][N],cnt,dis[M],deg[M];
int n,m;
bool vis[M];
struct edge{int v,w,nxt;}e[N*N*9];

void link(int x,int y,int w){e[++cnt] = (edge){y,w,h[x]};h[x] = cnt;}

void solve(){
	n = in;m = in;
	for(int i = 2;i <= n;i++)
		for(int j = 2;j <= m;j++) b[i][j] = in;
	memset(a,0,sizeof a);
	for(int i = 2;i <= n;i++)
		for(int j = 2;j <= m;j++) a[i][j] = b[i][j] - a[i-1][j] - a[i][j-1] - a[i-1][j-1];
	for(int i = 2;i <= n;i++)
		for(int j = 2;j <= m;j++) assert(a[i][j] + a[i-1][j] + a[i][j-1] + a[i-1][j-1] == b[i][j]);
	memset(dis,0,sizeof dis); cnt = 0; memset(h,0,sizeof h); memset(deg,0,sizeof deg); memset(vis,0,sizeof vis);
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= m;j++)
			if((i + j) & 1) link(i,j + n,a[i][j]),link(j + n,i,MX - a[i][j]);
			else link(j + n,i,a[i][j]),link(i,j + n,MX - a[i][j]);
	queue<int> q; for(int i = 1;i <= n + m;i++) q.push(i),vis[i] = 1;
	while(q.size()){
		int x = q.front(); q.pop(); deg[x]++; if(deg[x] > n + m + 1) return puts("NO"),void(); vis[x] = 0;
		for(int i = h[x],y;i;i = e[i].nxt){
			if(dis[y = e[i].v] > dis[x] + e[i].w){
				dis[y] = dis[x] + e[i].w;
				if(!vis[y]) q.push(y),vis[y] = 1;
			}
		}
	}
	puts("YES");
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= m;j++)
			printf("%d%c",a[i][j] + ((i + j) & 1 ? 1 : -1) * (dis[i] - dis[j + n])," \n"[j == m]);
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	for(int test = in;test;test--) solve();
	return 0;
}
